package com.fuhe.chen.vendingmachine.service.impl;

import com.fuhe.chen.vendingmachine.common.redis.RedisUtils;
import com.fuhe.chen.vendingmachine.dao.CommodityPictureDao;
import com.fuhe.chen.vendingmachine.pojo.CommodityPicture;
import com.fuhe.chen.vendingmachine.service.ICommodityPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import static com.fuhe.chen.vendingmachine.constant.CacheConstant.COMMODIIES_ALL_ON_SALE;

@Service
public class CommodityPictureServiceImpl implements ICommodityPictureService {

    @Autowired
    CommodityPictureDao commodityPictureDao;

    @Autowired
    RedisUtils redisUtils;


    @Override
    public List<CommodityPicture> queryCommodityPicture(Integer commodity_id) {
        redisUtils.delAll(COMMODIIES_ALL_ON_SALE);
        return commodityPictureDao.findByCommodityId(commodity_id);
    }

    @Override
    public void addCommodityPicture(CommodityPicture picture) {
        redisUtils.delAll(COMMODIIES_ALL_ON_SALE);
        commodityPictureDao.add(picture);
    }

    @Override
    public void updateCommodityPicture(CommodityPicture picture) {
        redisUtils.delAll(COMMODIIES_ALL_ON_SALE);
        commodityPictureDao.update(picture);
    }

    @Override
    public void deleteCommodityPicture(Integer id) {
        redisUtils.delAll(COMMODIIES_ALL_ON_SALE);
        commodityPictureDao.delete(id);
    }
}
